package
{
	import com.greensock.TweenLite;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.getTimer;
	
	// refactor menus
	// shopper ai gets stupid as mall gets bigger
	// Cheat mode - display cheater
	// Energy - use to get doobers
	// Maintenence
	// Motivation - evil level 1 mall owner heckles you - provide aspiration
	// steal other mall customers
	// Advisor
	
	
	public class mallsim extends Sprite
	{
		private var m_game:Game;
		private var m_lastTick:int;
		
		public function mallsim()
		{
			var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
			
			Game.stage = stage;
			Game.config = new Config();
			
			if(flashVars.clientFilesPath){
				Game.clientFilesPath = flashVars.clientFilesPath;	
			}
			
			if(flashVars.fbid){
				Game.fbid = flashVars.fbid;	
			} else {
				Game.fbid = '2043492'; // vinh's
			}
			
			ImageManager.startLoad(onImageManagerReady);
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.frameRate = 30;

			new Terminal(stage, onTerminalInput);
			
			m_lastTick = getTimer();
			
			alpha = 0;

		}
		
		private function onImageManagerReady():void{
			var game:Game = Game.instance = new Game();
			game.addEventListener(Event.INIT, onGameInitComplete);
			
			addChild(game.display);
			addChild(game.gameWorldOverlayLayer);
			addChild(game.hud.display);
			
		}
		
		private function onGameInitComplete(e:Event):void{
			TweenLite.to(this, 1, {alpha: 1});
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			Game.instance.centerDisplay();
			Game.instance.hud.updateNumberShoppers();
		}
		
		private function onEnterFrame(e:Event):void{
			var curTick:int = getTimer();
			var delta:int = curTick - m_lastTick;
			Game.instance.step(delta);
			m_lastTick = curTick;
		}
		
		private function onTerminalInput(input:String):void{
			m_game.command(input);
		}
	}
}